package com.fancy.learncenter.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.fancy.learncenter.activity.base.BaseActivity;
import com.fancy.learncenter.adapter.ReflectMoneyAdapter;
import com.fancy.learncenter.bean.BaseDataBean;
import com.fancy.learncenter.bean.UserAccountDataBean;
import com.fancy.learncenter.net.HttpMehtod;
import com.fancy.learncenter.net.IdeaObserver;
import com.superservice.lya.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

public class PayFlowActivity extends BaseActivity {


    @Bind(R.id.pay)
    TextView pay;
    @Bind(R.id.total_money)
    TextView totalMoney;
    @Bind(R.id.delete_money)
    TextView deleteMoney;
    @Bind(R.id.recycleView)
    RecyclerView recycleView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_flow, getResources().getColor(R.color.toolbar_color));
        ButterKnife.bind(this);
        initToolbar("账户明细");

        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycleView.setLayoutManager(linearLayoutManager);
        reflectMoneyAdapter = new ReflectMoneyAdapter(this, new ArrayList<UserAccountDataBean.DetailsBean>());
        recycleView.setAdapter(reflectMoneyAdapter);

        getAccount();
    }

    ReflectMoneyAdapter reflectMoneyAdapter;

    private void getAccount() {
        Map maps = new HashMap();
        HttpMehtod.getInstance().userWollet(maps, new IdeaObserver<BaseDataBean<UserAccountDataBean>>(this, true) {

            @Override
            public void onSuccess(BaseDataBean<UserAccountDataBean> stringBaseDataBean) {

                if (stringBaseDataBean.getData() != null) {


                    pay.setText("¥" + stringBaseDataBean.getData().getTotal_charge_coin());
                    totalMoney.setText("¥" + stringBaseDataBean.getData().getTotal_income_coin());
                    deleteMoney.setText("¥" + stringBaseDataBean.getData().getTotal_pay_coin());

                    if (stringBaseDataBean.getData().getDetails() != null) {
                        reflectMoneyAdapter.notifyDataSetChanged((ArrayList<UserAccountDataBean.DetailsBean>) stringBaseDataBean.getData().getDetails());
                    }
                }

            }

            @Override
            public void onFail(int errorCode) {

            }

        });
    }

}
